home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Resource for Source: C/C++
/
Resource for Source - C-C++.iso
/
codelib6
/
v_08_11
/
8n11105a
< prev
next >
Wrap
Text File
|
1995-11-01
|
906b
|
39 lines
******
Listing 4
#include <stdio.h>
struct s_date
{
int day;
int month;
char filler; /* Just to get some packing bytes (perhaps) */
int year;
};
main()
{
FILE *file;
static struct s_date date = {1,2,' ',3};
static struct s_date date2 = {4,5,' ',6};
printf("\n Size of the structure is %d",
sizeof(struct s_date));
/* Write two structures out */
file = fopen("DATA.DAT", "w");
fwrite(&date, sizeof(struct s_date), 1, file);
fwrite(&date2, sizeof(struct s_date), 1, file);
fclose(file);
file = fopen("DATA.DAT","r");
/* Note reversal of which date is read */
fread(&date2, sizeof(struct s_date), 1, file);
fread(&date, sizeof(struct s_date), 1, file);
fclose(file);
}
*********